package com.jiaai.web.zfp_back.privilege;

import com.alibaba.dubbo.config.annotation.Reference;
import com.jiaai.exception.ServerException;
import com.jiaai.gift.api.ICarApi;
import com.jiaai.gift.api.IGiftApi;
import com.jiaai.util.RestResultGenerator;
import com.jiaai.vip.api.IVIPApi;
import com.jiaai.vip.api.model.TVipVO;
import org.springframework.web.bind.annotation.*;

/**
 * class_name:ZBVipController
 * describe:TODO
 * create_user:张昉平
 * create_date:2018/1/2
 * create_date:10:32
 */
@RestController
@RequestMapping("/api/v1/admin/vip")
public class ZBVipController {

    @Reference
    private IVIPApi iVipApi;
    @Reference
    private IGiftApi iGiftApi;
    @Reference
    private ICarApi iCarApi;

    @RequestMapping("/list")
    public Object list()throws ServerException {
        try {
            return  RestResultGenerator.genSuccessResult(iVipApi.fidByAll());
        } catch (Exception e) {
            throw new ServerException("查询失敗");
        }
    }

//    @PostMapping("/saveoredit")
//    public Object saveOrEdit(@RequestBody VipVO vipVO)throws ServerException {
//        iVipApi.saveOrEdit(vipVO);
//        return  RestResultGenerator.genSuccessResult("操作成功");
//    }
//
//    @RequestMapping("/delete/{id}/{flag}")
//    public Object delete(@PathVariable("id") Integer id, @PathVariable("flag") Integer flag)throws ServerException {
//        iVipApi.delete(id, flag);
//        return  RestResultGenerator.genSuccessResult("操作成功");
//    }

    @GetMapping("/vipgift/{id}")
    public Object vipGift(@PathVariable("id") Integer id)throws ServerException {
        return  RestResultGenerator.genSuccessResult(null);
    }
//    @GetMapping("/vipgift/{id}")
//    public Object vipGift(@PathVariable("id") Integer id)throws ServerException {
//        return  RestResultGenerator.genSuccessResult(iGiftApi.getVipGifts(id));
//    }

    @GetMapping("/carxlk")
    public Object carXlk()throws ServerException {
        return  RestResultGenerator.genSuccessResult(iCarApi.xlkVip());
    }

    @PostMapping("/add")
    public Object pushMessage(@RequestBody TVipVO tVipVO) throws Exception{
        try {
            iVipApi.editVip(tVipVO);
            return RestResultGenerator.genSuccessResult("添加成功");
        } catch (Exception e) {
            return RestResultGenerator.genErrorResult("添加失败");
        }

    }
}
